<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-connector-edit" th:object="${connector}">
            <input id="apiConnectorId" name="apiConnectorId" th:field="*{apiConnectorId}"  type="hidden">
            <input name="apiDomainId"  type="hidden"  th:field="*{apiDomainId}" id="lookupId"/>
            <table width="100%">
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属项目：</label>
                            <div class="col-sm-8">
                                <input class="form-control" type="text" id="treeName" readonly="true" th:value="${project.description}"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">域名：</label>
                            <div class="col-sm-8">
                                <input id="lookupName" name="apiDomainId" readonly="true"  onclick="selectDomainList()" th:if="${connector.domain} ==null"  class="form-control" type="text">
                                <input id="lookupName" name="apiDomainId" readonly="true"  onclick="selectDomainList()" th:if="${connector.domain} !=null" th:value="*{domain?.named}+':'+*{domain?.port}+'['+*{domain?.description}+']'" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">接口url路径：</label>
                            <div class="col-sm-8">
                                <input id="urlContextpath" name="urlContextpath" th:field="*{urlContextpath}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">请求类型：</label>
                            <div class="col-sm-8">
                                <!--<input id="method"  name="method" class="form-control" type="text">-->
                                <select id="method" name="method" class="form-control m-b" th:with="type=${@dict.getType('api_http_method')}" th:field="*{method}">
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">接口名称：</label>
                            <div class="col-sm-8">
                                <input id="interfacename" name="interfacename" th:field="*{interfacename}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">接口描述：</label>
                            <div class="col-sm-8">
                                <input id="description" name="description" th:field="*{description}" class="form-control" type="text">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">创建者：</label>
                            <div class="col-sm-8">
                                <input id="createBy" name="createBy" th:field="*{createBy}" class="form-control" type="text" readonly="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">创建时间：</label>
                            <div class="col-sm-8">
                                <input id="createTime" name="createTime" th:field="*{createTime}" class="form-control" type="text" readonly="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">更新者：</label>
                            <div class="col-sm-8">
                                <input id="updateBy" name="updateBy" th:field="*{updateBy}" class="form-control" type="text" readonly="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">更新时间：</label>
                            <div class="col-sm-8">
                                <input id="updateTime" name="updateTime" th:field="*{updateTime}" class="form-control" type="text" readonly="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-8">
                                <!--<input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">-->
                                <textarea  id="remark" name="remark" th:field="*{remark}" class="form-control"  rows="3" cols="20"></textarea>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">请求参数说明：</label>
                            <div class="col-sm-8">
                                <input id="parameters" name="parameters" th:field="*{parameters}" type="hidden">
                                <div id="editor_parameters" name="editor_parameters" class="summernote"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">请求主体信息：</label>
                            <div class="col-sm-8">
                                <input id="postbody" name="postbody" th:field="*{postbody}" type="hidden">
                                <div id="editor_postbody" name="editor_postbody" class="summernote"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">返回信息：</label>
                            <div class="col-sm-8">
                                <input id="result" name="result" th:field="*{result}" type="hidden">
                                <div id="editor_result" name="editor_result" class="summernote"></div>
                            </div>
                        </div>
                        <!--<div id="show_content" th:utext="*{parameters}"></div>-->
                    </td>
                </tr>
            </table>
            <div class="form-group">
                <div class="form-control-static col-sm-offset-9">
                    <button type="submit" class="btn btn-primary">提交</button>
                    <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
                </div>
            </div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
    <script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
    <script type="text/javascript">
        $(function() {
            var editor_heigth='320px';
            $('#editor_parameters').summernote({
                height : editor_heigth,
                lang : 'zh-CN'
            });
            var content = $("#parameters").val();
            $('#editor_parameters').code(content);

            $('#editor_postbody').summernote({
                height : editor_heigth,
                lang : 'zh-CN'
            });
            var content = $("#postbody").val();
            $('#editor_postbody').code(content);

            $('#editor_result').summernote({
                height : editor_heigth,
                lang : 'zh-CN'
            });
            var content = $("#result").val();
            $('#editor_result').code(content);

        });

    </script>
    <script type="text/javascript">
		var prefix = ctx + "module/connector"
		$("#form-connector-edit").validate({
			rules:{
                apiProjectnameId:{
                    required:true,
                },
                description:{
                    required:true,
                },
                method:{
                    required:true,
                },
                interfacename:{
                    required:true,
                },
			},
			submitHandler: function(form) {
                var sHTML = $('#editor_parameters').code();
                $("#parameters").val(sHTML);
                var sHTML = $('#editor_result').code();
                $("#result").val(sHTML);
                var sHTML = $('#editor_postbody').code();
                $("#postbody").val(sHTML);
				$.operate.save(prefix + "/edit", $('#form-connector-edit').serialize());
			}
		});
        /*选择域名列表*/
        function selectDomainList() {
            var lookupId = $("#lookupId").val();
            if(lookupId == ""||lookupId==undefined){
                lookupId=-1;
            }
            var url = ctx + "module/domain/lookupDomainList/"+lookupId;
            var options = {
                title: '域名管理',
                width: "380",
                height: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#lookupId").val(body.find('#lookupId').val());
            $("#lookupName").val(body.find('#lookupName').val());
            layer.close(index);
        }
	</script>
</body>
</html>
